package cn.iocoder.yudao.module.dt.controller.admin.sumbitcolums;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.dt.controller.admin.sumbitcolums.vo.*;
import cn.iocoder.yudao.module.dt.dal.dataobject.sumbitcolums.SumbitColumsDO;
import cn.iocoder.yudao.module.dt.convert.sumbitcolums.SumbitColumsConvert;
import cn.iocoder.yudao.module.dt.service.sumbitcolums.SumbitColumsService;

@Api(tags = "管理后台 - 活动提交字段表，用户提交需要填写哪儿些字段")
@RestController
@RequestMapping("/dt/sumbit-colums")
@Validated
public class SumbitColumsController {

    @Resource
    private SumbitColumsService sumbitColumsService;

    @PostMapping("/create")
    @ApiOperation("创建活动提交字段表，用户提交需要填写哪儿些字段")
    @PreAuthorize("@ss.hasPermission('dt:sumbit-colums:create')")
    public CommonResult<Integer> createSumbitColums(@Valid @RequestBody SumbitColumsCreateReqVO createReqVO) {
        return success(sumbitColumsService.createSumbitColums(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新活动提交字段表，用户提交需要填写哪儿些字段")
    @PreAuthorize("@ss.hasPermission('dt:sumbit-colums:update')")
    public CommonResult<Boolean> updateSumbitColums(@Valid @RequestBody SumbitColumsUpdateReqVO updateReqVO) {
        sumbitColumsService.updateSumbitColums(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除活动提交字段表，用户提交需要填写哪儿些字段")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('dt:sumbit-colums:delete')")
    public CommonResult<Boolean> deleteSumbitColums(@RequestParam("id") Integer id) {
        sumbitColumsService.deleteSumbitColums(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得活动提交字段表，用户提交需要填写哪儿些字段")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('dt:sumbit-colums:query')")
    public CommonResult<SumbitColumsRespVO> getSumbitColums(@RequestParam("id") Integer id) {
        SumbitColumsDO sumbitColums = sumbitColumsService.getSumbitColums(id);
        return success(SumbitColumsConvert.INSTANCE.convert(sumbitColums));
    }

    @GetMapping("/list")
    @ApiOperation("获得活动提交字段表，用户提交需要填写哪儿些字段列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('dt:sumbit-colums:query')")
    public CommonResult<List<SumbitColumsRespVO>> getSumbitColumsList(@RequestParam("ids") Collection<Integer> ids) {
        List<SumbitColumsDO> list = sumbitColumsService.getSumbitColumsList(ids);
        return success(SumbitColumsConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得活动提交字段表，用户提交需要填写哪儿些字段分页")
    @PreAuthorize("@ss.hasPermission('dt:sumbit-colums:query')")
    public CommonResult<PageResult<SumbitColumsRespVO>> getSumbitColumsPage(@Valid SumbitColumsPageReqVO pageVO) {
        PageResult<SumbitColumsDO> pageResult = sumbitColumsService.getSumbitColumsPage(pageVO);
        return success(SumbitColumsConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出活动提交字段表，用户提交需要填写哪儿些字段 Excel")
    @PreAuthorize("@ss.hasPermission('dt:sumbit-colums:export')")
    @OperateLog(type = EXPORT)
    public void exportSumbitColumsExcel(@Valid SumbitColumsExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<SumbitColumsDO> list = sumbitColumsService.getSumbitColumsList(exportReqVO);
        // 导出 Excel
        List<SumbitColumsExcelVO> datas = SumbitColumsConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "活动提交字段表，用户提交需要填写哪儿些字段.xls", "数据", SumbitColumsExcelVO.class, datas);
    }

}
